package com.lingyu.jsjx.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.lingyu.jsjx.domain.UserDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.lingyu.jsjx.domain.DocumentFavorite;
import com.lingyu.jsjx.service.IDocumentFavoriteService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 收藏
Controller
 * 
 * @author ruoyi
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/documentFavorite")
public class DocumentFavoriteController extends BaseController
{
    @Autowired
    private IDocumentFavoriteService documentFavoriteService;

    /**
     * 查询收藏列表
     */
    @RequiresPermissions("jsjx:documentFavorite:list")
    @GetMapping("/list")
    public TableDataInfo list(UserDocument userDocument)
    {
        startPage();
        List<DocumentFavorite> list = documentFavoriteService.selectDocumentFavoriteList(userDocument);
        return getDataTable(list);
    }

    /**
     * 导出收藏列表
     */
    @RequiresPermissions("jsjx:documentFavorite:export")
    @Log(title = "收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,UserDocument userDocument)
    {
        List<DocumentFavorite> list = documentFavoriteService.selectDocumentFavoriteList(userDocument);
        ExcelUtil<DocumentFavorite> util = new ExcelUtil<DocumentFavorite>(DocumentFavorite.class);
        util.exportExcel(response, list, "收藏数据");
    }

    /**
     * 获取收藏详细信息
     */
    @RequiresPermissions("jsjx:documentFavorite:query")
    @GetMapping(value = "/{favoriteId}")
    public AjaxResult getInfo(@PathVariable("favoriteId") Long favoriteId)
    {
        return success(documentFavoriteService.selectDocumentFavoriteByFavoriteId(favoriteId));
    }

    /**
     * 新增收藏
     */
    @RequiresPermissions("jsjx:documentFavorite:add")
    @Log(title = "收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DocumentFavorite documentFavorite)
    {
        return toAjax(documentFavoriteService.insertDocumentFavorite(documentFavorite));
    }

    /**
     * 修改收藏
     */
    @RequiresPermissions("jsjx:documentFavorite:edit")
    @Log(title = "收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DocumentFavorite documentFavorite)
    {
        return toAjax(documentFavoriteService.updateDocumentFavorite(documentFavorite));
    }

    /**
     * 删除收藏
     */
    @RequiresPermissions("jsjx:documentFavorite:remove")
    @Log(title = "收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{favoriteIds}")
    public AjaxResult remove(@PathVariable Long[] favoriteIds)
    {
        return toAjax(documentFavoriteService.deleteDocumentFavoriteByFavoriteIds(favoriteIds));
    }
}
